/*
 * Copyright 2012 Ufonzak.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cz.muni.fi.heathtow.web.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author Ufonzak
 */
public class Utils
{
    public static final String DATE_FORMAT = "dd. MM. yyyy";
    public static final String TIME_FORMAT = "HH:mm";
    
    public static void parseDate(String strDate, String strTime, Calendar c) throws ParseException
    {
        DateFormat formDate = new SimpleDateFormat(DATE_FORMAT);
        DateFormat formTime = new SimpleDateFormat(TIME_FORMAT);
        Date dt = formDate.parse(strDate);
        Date time = formTime.parse(strTime);
        c.set(dt.getYear(), dt.getMonth(), dt.getDate(), time.getHours(), time.getMinutes(), 0);        
    }
    
    public static String FormatDate(Calendar c)
    {    
        DateFormat formDate = new SimpleDateFormat(DATE_FORMAT);
        return formDate.format(c.getTime());
    }
    
    public static String FormatTime(Calendar c)
    {    
        DateFormat formDate = new SimpleDateFormat(TIME_FORMAT);
        return formDate.format(c.getTime());
    }
    
    public static String FormatDateTime(Calendar c)
    {    
        DateFormat formDate = new SimpleDateFormat(DATE_FORMAT + " " + TIME_FORMAT);
        return formDate.format(c.getTime());
    }
}
